/*
 * data.h
 *
 *  Created on: Mar 12, 2013
 *      Author: abrahamsantini
 */

#ifndef DATA_H_
#define DATA_H_

#include "calculator.h"
#include "producer.h"
#include "consumer.h"
#include "sharedMemory.h"

struct data_t;
typedef struct data_t tdata_t;

struct data_t{
	calculator_t *my_calc;
	producer_t *my_prod;
	consumer_t *my_cons;
	int (* funct)(tdata_t *data);
	int my_io;
	int my_io_counter;
};

//*************** CALCULATOR FUNCTIONS*************
int init_data(tdata_t *data, sharedMemory_t *sm);

int get_value(tdata_t *data);

int square_value(tdata_t *data);

int mod_value(tdata_t *data);

int return_value(tdata_t *data);

int next_calc_instr(tdata_t *data);

int get_calc_cycles(tdata_t *data);

//*************** PRODUCER FUNCTIONS*************
//functions to acquire resources returns -1 if resource can't be acquired
//either because stack is full or resource has been locked by another process
int get_prod_tos(tdata_t *data);
int get_prod_stack(tdata_t *data);
int get_prod_sm_value(tdata_t *data);

//functions to manipulate resources
int push_stack(tdata_t *data);

//functions to return resources
int return_prod_tos(tdata_t *data);
int return_prod_stack(tdata_t *data);
int return_prod_sm_value(tdata_t *data);

int next_pro_instr(tdata_t *data);
int get_prod_cycles(tdata_t *data);

//*************** CONSUMER FUNCTIONS*************

//functions to acquire resources returns -1 if resource can't be acquired
//either because stack is full or resource has been locked by another process
int get_con_tos(tdata_t *data);
int get_con_stack(tdata_t *data);
int get_con_sm_value(tdata_t *data);

//functions to manipulate resources
int pop_stack(tdata_t *data);

//functions to return resources
int return_con_tos(tdata_t *data);
int return_con_stack(tdata_t *data);
int return_con_sm_value(tdata_t *data);
int next_con_instr(tdata_t *data);

int get_con_cycles(tdata_t *data);

int set_io_1(tdata_t *data);
void set_io_0(tdata_t *data);
int print_message (tdata_t *data);

#endif /* DATA_H_ */
